var to = document.querySelector('.to');
var bo = document.querySelector('.bo');
var table1 = document.querySelector('.logon');
var table2 = document.querySelector('.register');
var sanjiao = document.querySelector('.sanjiao');
var flag1=0;
var flag2=0;
var flag3=0;

var box1 = document.getElementById('pa1');
var input1 = box1.getElementsByTagName('input')[0];
var img1 = box1.getElementsByTagName('img')[0];

var box2 = document.getElementById('pa2');
var input2 = box2.getElementsByTagName('input')[0];
var img2 = box2.getElementsByTagName('img')[0];

var box3 = document.getElementById('pa3');
var input3 = box3.getElementsByTagName('input')[0];
var img3 = box3.getElementsByTagName('img')[0];
to.onclick = function(){
    table1.style.display = 'block';
    table2.style.display = 'none';
    to.style.backgroundColor = 'rgb(130, 172, 235)';
    bo.style.backgroundColor = 'rgba(130, 172, 235,0)';
    sanjiao.style.top = 0;
}
bo.onclick = function(){
    table1.style.display = 'none';
    table2.style.display = 'block';
    to.style.backgroundColor = 'rgba(130, 172, 235,0)';
    bo.style.backgroundColor = 'rgb(130, 172, 235)';
    sanjiao.style.top = '250px';
}
 
img1.onclick = function(){
    if(flag1==0){
        // console.log(eye_input1.children[1]);
        img1.src = "../img/zhengyan.png";
        // console.log(eye_input1.children[0]);
        input1.type = "text";
        flag1 = 1;
    }
    else{
        img1.src = '../img/biyan.png';
        input1.type = 'password';
        flag1 = 0;
    }
};

img2.onclick = function(){
    if(flag2==0){
        // console.log(eye_input1.children[1]);
        img2.src = "../img/zhengyan.png";
        // console.log(eye_input1.children[0]);
        input2.type = "text";
        flag2 = 1;
    }
    else{
        img2.src = '../img/biyan.png';
        input2.type = 'password';
        flag2 = 0;
    }
};

img3.onclick = function(){
    if(flag3==0){
        // console.log(eye_input1.children[1]);
        img3.src = "../img/zhengyan.png";
        // console.log(eye_input1.children[0]);
        input3.type = "text";
        flag3 = 1;
    }
    else{
        img3.src = '../img/biyan.png';
        input3.type = 'password';
        flag3 = 0;
    }
};

var contain = document.querySelector('.container');
var value1 = document.getElementById('username1');
var value2 = document.getElementById('username2');
var btn1 = document.getElementById('btn1');
var btn2 = document.getElementById('btn2');
btn1.onclick = function(){
    localStorage.setItem('username',value1.value);
}
btn2.onclick = function(){
    localStorage.setItem('username',value2.value);
}

// 1、保存数据到本地
// 第一个参数是保存的变量名，第二个是赋给变量的值
// localStorage.setItem('Author', 'local');
// 2、从本地存储获取数据
// localStorage.getItem('Author');
// 3、从本地存储删除某个已保存的数据
// localStorage.removeItem('Author');
// 4、清除所有保存的数据
// localStorage.clear();

// 注册部分
var ok2_1 = true;
var ok2_2 = true;
function check1(){
    if(input2.value!=input3.value){
            alert('两次输入密码不一致');
            ok2_1=false;
    }
    else{
        ok2_1 = true;
    }
}
input3.addEventListener('blur',check1);

function check2(){
    if((document.querySelector('#username2').value=='')||(input2.value=='')||(input3.value=='')){
        ok2_2 = false;
        alert('请将信息补充完整');
    }
    else{
        ok2_2=true;
    }
}
function sure2(){
    if(ok2_1&&ok2_2){
        btn2.querySelector('a').href = './index.html';
    }
    else{
        btn2.querySelector('a').href = '###';
    }
}
btn2.addEventListener('click',check2);
btn2.addEventListener('click',sure2);

// 登录部分
var ok1_1 = true;
function check0(){
    if((document.querySelector('#username1').value=='')||(input1.value=='')){
        ok1_1 = false;
        alert('请将信息补充完整');
    }
    else{
        ok1_1 = true;
    }
}
function sure1(){
    if(ok1_1){
        btn1.querySelector('a').href = './index.html';
    }
    else{
        btn1.querySelector('a').href = '###';
    }
}
btn1.addEventListener('click',check0);
btn1.addEventListener('click',sure1);